<?php
/**
 * CreateTime: 2022/5/26 15:52
 */

namespace App\ServiceChecker\newContract;

use App\Consts\ContractConsts\NewFulfillmentStatusConsts;
use App\Consts\ResponseConsts\ResponseStatusConsts;
use App\Func\ResponseFunc;
use App\Models\NewContract\ContractModel;
use App\Models\NewContract\FulfillmentModel;
use App\ServiceChecker\BasicServiceChecker;
use Illuminate\Http\Exceptions\HttpResponseException;

class FulfillmentLegitimacy extends BasicServiceChecker
{
    private $contractModel;
    private $fulfillmentModel;

    public function __construct()
    {
        parent::__construct();
        $this->contractModel = new ContractModel();
        $this->fulfillmentModel = new FulfillmentModel();
    }

    public function verifyFulfillmentIsExists($fulfillmentId){
        $isExist = $this->fulfillmentModel->isExistByCondition([
            'fulfillment_id' => $fulfillmentId,
            'fulfillment_status' => NewFulfillmentStatusConsts::FULFILLMENT_STATUS_DLY
        ]);

        if(!$isExist){
            throw new HttpResponseException( ResponseFunc::returnJson(
                'error',
                null,
                '当前履约不存在或已完成',
                ResponseStatusConsts::OK_200_RESPONSE_STATUS,
            ));
        }
    }



    public function verifyContractIsExist($contractId){
        $isExist =  $this->contractModel->isExistByCondition([
            'contract_id' => $contractId
        ]);
        if(!$isExist){
            throw new HttpResponseException( ResponseFunc::returnJson(
                'error',
                null,
                '绑定合同不存在',
                ResponseStatusConsts::OK_200_RESPONSE_STATUS,
            ));
        }
    }

}